package com.study.jyg.rxjava2study.activity.wifidevicesearch.pingwifiip;


import android.text.TextUtils;
import android.widget.TextView;

import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.base.BasicActivity;
import com.study.jyg.rxjava2study.utils.ToastUtils;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class WifiPingActivity extends BasicActivity implements NetToolTask.NetToolTaskListener {


    private TextView tv1;

    @Override
    protected boolean isUseThemestatusBarColor() {
        return true;
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_wifi_ping;
    }

    @Override
    protected void initView() {
        tv1 = findViewById(R.id.tv1);

        for (int i = 0; i < 256; i++) {
            NetToolTask task = new NetToolTask();
            task.setNetToolTaskListener(this);
            task.executeOnExecutor(Executors.newCachedThreadPool(), i);
        }
    }


    @Override
    public void linkSuccess(String ip) {
        String text = tv1.getText().toString();
        if (TextUtils.isEmpty(text)){
            tv1.setText(ip);
        }else {
            tv1.setText(String.format("%s\n%s", text, ip));
        }
    }

    @Override
    public void sendMsgSuccess(String result) {
        String text = tv1.getText().toString();
        if (TextUtils.isEmpty(text)){
            tv1.setText(result);
        }else {
            tv1.setText(String.format("%s\n%s", text, result));
        }
    }
}